package br.ufpe.cin.dsoa.broker.impl;

import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import br.ufpe.cin.dsoa.broker.ServiceDescription;
import br.ufpe.cin.dsoa.broker.ServiceMetadata;

public class Util {
	public static ServiceDescription getServiceDescription(BundleContext context, ServiceReference reference) {
		String providerId = reference.getProperty("provider.pid").toString();
		Map<String, Object> properties = new HashMap<String, Object>();
		for (String key : reference.getPropertyKeys()){
			properties.put(key, reference.getProperty(key));
		}
		ServiceMetadata sm = new ServiceMetadataImpl(providerId, properties);
		ServiceDescription sd = new ServiceDescriptionImpl(context.getService(reference), sm);
		return sd;
	}
}
